home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE21 / EX12.C < prev    next >
C/C++ Source or Header  |  1995-05-29  |  2KB  |  44 lines

  1. #include <genstub.c>
  2. #include <pbt.h>
  3.  
  4. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5. {
  6.    switch (uMsg)
  7.    {
  8.          case WM_COMMAND:
  9.                switch ( LOWORD( wParam ) )
  10.                {
  11.                    case IDM_TEST:  // Query suspend power.
  12.                          SetSystemPowerState( FALSE, FALSE );
  13.                          break;
  14.                    case IDM_EXIT:
  15.                          DestroyWindow( hWnd );
  16.                          break;
  17.                }
  18.                break;
  19.          case WM_POWERBROADCAST:
  20.                if ( wParam == PBT_APMQUERYSUSPEND )
  21.                {
  22.                   SYSTEM_POWER_STATUS sps;
  23.  
  24.                   GetSystemPowerStatus( &sps );
  25.                   // if not on ACLine & less than 10 percent, let suspend.
  26.                   if (!sps.ACLineStatus && sps.BatteryLifePercent<10 )
  27.                   {
  28.                      int iResponse = MessageBox( hWnd, "Do you want to suspend?",
  29.                                                  "Query Suspend State", MB_YESNO );
  30.                      if ( iResponse == IDYES )
  31.                         return TRUE;
  32.                      else
  33.                         return FALSE;
  34.                   }
  35.                }
  36.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  37.          case WM_DESTROY:
  38.                PostQuitMessage( 0 );
  39.                break;
  40.          default:
  41.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  42.    }
  43.    return (NULL);
  44. }